import java.nio.channels.spi.SelectorProvider;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-03-26
 * Time: 8:45
 */
public class Test2 {
    public static  Object object = new Object();


    public static void main3(String[] args) {
        Thread ta = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(3 * i + 2);
                    System.out.println("a");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread tb = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(3 * i + 1);
                    System.out.print("b");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread tc = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(i * 3);
                    System.out.print("c");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        tc.start();
        tb.start();
        ta.start();
    }

    public static void main(String[] args) {
        Thread ta = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                synchronized (object) {
                    try {
                        object.wait(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.print("A");
                    object.notify();
                }
            }
        });
        Thread tb = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                synchronized (object) {
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.print("B");
                    object.notify();
                }
            }
        });
        Thread tc = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                synchronized (object) {
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("C");
                    object.notify();
                }
            }
        });
        ta.start();
        tb.start();
        tc.start();
    }
}
